#include <stdio.h>
#include <stdlib.h>
#include "mpi.h"

int main(int argc, char **argv)
{
	MPI_Status status;
	int rank, procnum, base;
	long   MAX_NUM, range;
	char *endptr;
	if(argc<2)
	{
		printf("USAGE: %s num\n",argv[0]);
		exit(0);
	}
	  
          //MAX_NUM = strtol(argv[1],&endptr);
          MAX_NUM = atoi(argv[1]);

	MPI_Init(&argc, &argv);
	MPI_Comm_size(MPI_COMM_WORLD,&procnum);
	MPI_Comm_rank(MPI_COMM_WORLD,&rank);
	  range = MAX_NUM/(procnum-1);
int send=0;
int res=0;
if(rank!=0)
{send = rank;
MPI_Send(&send,1,MPI_INT,0,0,MPI_COMM_WORLD);
printf("%d\n",rank);
}


MPI_Reduce(&send,&res,1,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD);
if(rank==0)
printf("result %d \n",res);

	MPI_Finalize();
//	exit(0);
return 0;
}
